package com.example.myapplication2003;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import com.example.myapplication2003.adapter.CartAdapter;
import com.example.myapplication2003.bean.Product;

import java.util.ArrayList;
import java.util.List;

public class CartActivity extends AppCompatActivity {

    String[] names = new String[]{"中国十大名茶", "全自动雨伞", "蓝色军刀"};
    int[] types = new int[] {0, 1, 1};
    int[] prices = new int[] {149, 328, 469};
    int[] countes = new int[] {2, 1, 1};
    int[] images = new int[] {R.drawable.tea, R.drawable.umbrella, R.drawable.bag};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cart);

        //=========================================
        // 取数据
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        int age = intent.getIntExtra("age", 0);

        Log.i("tag", name +"");
        Log.i("tag", age+"");
        //=============================================



        // 定义模拟数据
        List<Product> list = new ArrayList<>();
        for(int i=0; i<3; i++) {
            list.add(new Product(images[i], names[i], types[i], prices[i], countes[i]));
        }

        //初始化adapter
        CartAdapter cartAdapter =
                new CartAdapter(this,R.layout.cart_listview_item,list);
        // 关联listview
        ListView listView = findViewById(R.id.list_view);
        listView.setAdapter(cartAdapter);   // 关联
    }
}